import {MC_MANAGE_AXIOS} from '@/api/axios'

// POST - 添加一条记录
export function saveApi(params) {
    return MC_MANAGE_AXIOS.post('/room/save', params, {headers: {'Content-Type': 'application/json'}})
}

// GET - 查询一条记录
export function getInfoApi(id) {
    return MC_MANAGE_AXIOS.get('/room/getInfo/' + id)
}

// POST - 分页查询记录
export function pageApi(params) {
    return MC_MANAGE_AXIOS.post('/room/page', params, {headers: {'Content-Type': 'application/json'}});
}

// POST - 修改一条记录
export function updateApi(params) {
    return MC_MANAGE_AXIOS.post('/room/update', params, {headers: {'Content-Type': 'application/json'}})
}

// POST - 删除一条记录
export function removeApi(id) {
    return MC_MANAGE_AXIOS.post('/room/remove/' + id)
}

// POST - 批量删除记录
export function removeBatchApi(ids) {
    return MC_MANAGE_AXIOS.post('/room/removeBatch?ids=' + ids)
}

// GET - 查询全部记录
export function listApi() {
    return MC_MANAGE_AXIOS.get('/room/list')
}

// GET - 下载Excel报表
export function excelApi(url, fileName) {
    // 后缀自动拼接
    if (!fileName.endsWith('.xlsx')){
        fileName += '.xlsx';
    }
    // 发送下载请求，响应类型：blob
    return MC_MANAGE_AXIOS.get(url,{
        responseType: 'blob'
    }).then(res => {
        let url = URL.createObjectURL(new Blob([res.data]));
        // 借助超链接标签完成下载功能
        let a = document.createElement('a');
        a.style.display = 'none';
        a.href = url;
        a.setAttribute('download', fileName);
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
        a = null;
    });
}

// POST - 模糊查询
export function dimSelectApi(params){
    return MC_MANAGE_AXIOS.post('room/dimSelect', params, {headers: {'Content-Type': 'application/json'}})
}


